package com.example.threadcode.basicLeverFour.InheritableThreadLocalDemo;

import java.util.Timer;

public class InheritableThreadLocalDemo
{
   private static final InheritableThreadLocal<Integer> intVal =
      new InheritableThreadLocal<Integer>();

   public static void main(String[] args) throws InterruptedException {
      Runnable rP = () ->
                    {
//                      这父线程中设置值
//                       intVal.set(new Integer(10));
                       Runnable rC = () ->
                                     {
                                        Thread thd = Thread.currentThread();
                                        String name = thd.getName();
//                                        子线程中取值.证明父传子.
                                        System.out.printf("%s %d%n", name,
                                                          intVal.get());
                                     };
                       Thread thdChild = new Thread(rC);
                       thdChild.setName("Child");
                       thdChild.start();
                    };
       Thread thread = new Thread(rP);
       thread.start();
   }
}